package com.liu.susu.controller.asny.asny2;

import com.liu.susu.thread.task.async.async2.config.LiuTaskExecutorConfig2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @FileName PoolTestController
 * @Description
 * @Author susu
 * @date 2022-03-09
 **/
@Controller
@Slf4j
public class LiuTaskExecutorConfig2Controller {

    ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) LiuTaskExecutorConfig2.getSuSuAsyncTaskExecutor2();

    @ResponseBody
    @RequestMapping("/info")
    public String getThreadPoolExecutorInfo(){

        ThreadPoolExecutor threadPoolExecutor = taskExecutor.getThreadPoolExecutor();

        log.info("\n==>{}, corePoolSize [{}], maximumPoolSize [{}], " +
                        "taskCount [{}], completedTaskCount [{}], activeCount [{}], " +
                        "queueSize [{}]\n",
                taskExecutor.getThreadNamePrefix(),
                threadPoolExecutor.getCorePoolSize(),
                threadPoolExecutor.getMaximumPoolSize(),
                threadPoolExecutor.getTaskCount(),
                threadPoolExecutor.getCompletedTaskCount(),
                threadPoolExecutor.getActiveCount(),
                threadPoolExecutor.getQueue().size());

        return "ok";
    }


}
